package com.xinxin.socket.sample.handler;

import com.xinxin.socket.handler.NetMsgHandler;
import com.xinxin.socket.msg.NetMsg;
import com.xinxin.socket.sample.context.TopicContext;
import io.netty.channel.ChannelHandlerContext;

/**
 * @author ys
 * @date 2020/8/7
 */
public class TopicHandler extends NetMsgHandler {

    private final TopicContext topicContext = TopicContext.getInstance();

    @Override
    public void channelActive(ChannelHandlerContext ctx) {
        topicContext.joinTopic(ctx.channel());

        ctx.fireChannelActive();

        ctx.channel().closeFuture().addListener(future -> topicContext.leftTopic(ctx.channel()));
    }

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, NetMsg netMsg) {
    }
}
